package edu.nf.project.mappers.other;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.entity.other.Message;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper extends BaseMapper<Message> {
    /**
     * 获取两个用户之间的聊天记录
     * @param sender 发送者ID
     * @param receiver 接收者ID
     * @return 消息列表
     */
    @Select("SELECT * FROM messages WHERE (sender = #{sender} AND receiver = #{receiver}) " +
            "OR (sender = #{receiver} AND receiver = #{sender}) ORDER BY send_time DESC")
    List<Message> getMessagesBySenderAndReceiver(String sender, String receiver);

    /**
     * 获取接收者的所有聊天记录
     * @param receiver 接收者ID
     * @return 消息列表
     */
    @Select("SELECT * FROM messages WHERE receiver = #{receiver} ORDER BY send_time DESC")
    List<Message> getAllMessagesByReceiver(String receiver);
}
